# -*- coding: utf-8 -*-
from pandas import Series

from core.enums import TrendEnum


def direction(data: Series) -> TrendEnum:
    if data.count() < 2:
        return None
    elif data.count() == 2:
        if data[-1] > data[-2]:
            return TrendEnum.ROSE
        elif data[-1] == data[-2]:
            return TrendEnum.HORIZONTALLY
        else:
            return TrendEnum.FELL
    else:
        sum = 0
        if data[-1] > data[-2]:
            sum = sum + 1
        elif data[-1] < data[-2]:
            sum = sum - 1
        if data[-2] > data[-3]:
            sum = sum + 1
        elif data[-2] < data[-3]:
            sum = sum - 1
        if data.count() > 5:
            if data[-3] > data[-4]:
                sum = sum + 1
            elif data[-3] < data[-4]:
                sum = sum - 1
            if data[-4] > data[-5]:
                sum = sum + 1
            elif data[-4] < data[-5]:
                sum = sum - 1
        if sum > 0:
            return TrendEnum.ROSE
        elif sum < 0:
            return TrendEnum.FELL
        else:
            return TrendEnum.HORIZONTALLY